import java.util.Calendar;
import java.util.Timer;


public class Soloing extends Thread {

	public long lastSoloOnset;
	public int loopCounter=0;
	@Override
	public void run() {
		while(true){
			int pointer = Main.notesArrayPointer;
			int onsetCounter=0;
			int timeCounter=0;
			while (pointer>4&&timeCounter<2000){
				if (Main.notesArray[pointer-1][2]>40){ // if not simultaneity 
					onsetCounter = onsetCounter + 1;
					timeCounter=timeCounter+Main.notesArray[pointer-1][2];

				}
				pointer=pointer-1;
			}
			if (onsetCounter>9&&loopCounter>2){
				if (Main.improvise.soloing==false){
					loopCounter=0;
					lastSoloOnset=Calendar.getInstance().getTimeInMillis();
				}
				Main.improvise.soloing=true;
				Main.improvise.learnSoloing=true;
				System.out.println("soloing=true!!!!");
			}
			if (onsetCounter<8&&loopCounter>2&&onsetCounter>0){
				if (Main.improvise.soloing==true){
					loopCounter=0;
					Timer timer = new Timer();
					StopPlaying stopPlaying = new StopPlaying();
					timer.schedule(stopPlaying, (Calendar.getInstance().getTimeInMillis()-lastSoloOnset));
				}
				Main.improvise.soloing=false;
				Main.improvise.learnSoloing=false;
			}
			System.out.println("Count ="+onsetCounter);
			
			loopCounter=loopCounter+1;
			
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
}
